//
//  Database.h
//  cliqset
//
//  Created by David Hinson on 2/16/09.
//  Copyright 2009 Cliqset, Inc.. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "sqlite3.h"
#import "Contact.h"

@interface Database : NSObject {

}

-(void)clearTables;	

-(void)addFavorite:(NSString*)uid cid:(NSString*)cid;
- (void)createEditableCopyOfDatabaseIfNeeded;
-(void)createMessagesTable;
-(BOOL)databaseNeedsUpdate;
-(NSString*)getDatabasePath;
-(NSString*)getEventsDatabasePath;
-(NSString*)getProfileEventsDatabasePath;
-(NSString*)getCachedMessagesDatabasePath;
-(NSString*)getRelationshipsDatabasePath;
-(int)isContactAFavorite:(NSString*)uid cid:(NSString*)cid;
-(void)loadContactsFromDatabase:(NSString *)uid;
-(void)loadEventsFromDatabase:(NSString *)uid;
-(void)loadFavorites:(NSString*)uid;
-(void)loadCountriesFromDatabase:(int)index code:(NSMutableString**)code name:(NSMutableString**)name;
-(int)countCountriesFromDatabase;
-(int)countContactsFromDatabase;
-(int)countEventsFromDatabase;

#pragma mark ---- puts ----
-(void)putEmailAddress:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag content:(NSString*)content flag:(BOOL)flag;
-(void)putPhone:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag content:(NSString*)content flag:(BOOL)flag;
-(void)putIM:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag content:(NSString*)content flag:(BOOL)flag;
-(void)putURL:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag content:(NSString*)content;
-(void)putAddress:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag street:(NSString*)street locality:(NSString*)locality region:(NSString*)region postalCode:(NSString*)postalCode country:(NSString*)country;
-(void)putContact:(Contact*)contact;

#pragma mark ---- removes ----
-(void)removeAddress:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag;
-(void)removeContact:(NSString*)uid cid:(NSString*)cid;
-(void)removeEmailAddress:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag;
-(void)removeIM:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag;
-(void)removePhone:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag;
-(void)removeURL:(NSString*)uid cid:(NSString*)cid tag:(NSString *)tag;
-(void)removeFavorite:(NSString*)uid cid:(NSString*)cid;
-(void)removeUpdateFavorite:(sqlite3*)database uid:(NSString*)uid cid:(NSString*)cid;

#pragma mark ---- messages ----
-(void)saveMessages;
-(void)loadMessageFromDatabase;
-(void)deleteMessage:(NSString*)messageIdentifier;
-(void)markMessageRead:(NSString*)messageIdentifier;

#pragma mark ---- misc ----
-(void)resetTimestamp;
-(void)saveContactsToDatabase;
-(void)saveEventsToDatabase;
-(NSString*)getLatestEventDateFromDatabase;
-(NSString*)getLatestContactDateFromDatabase;

#pragma mark ---- Profile Events ----
// --- djh 04/22/2009
-(void)createProfileEventsTable;
-(void)saveProfileEventsToDatabase;
-(void)populateProfileEventsTables:(sqlite3 *)database index:(int)index;
-(void)populateProfileEvents:(sqlite3*) database index:(int)index;
-(void)populateProfileResources:(sqlite3*) database index:(int)index;
-(void)loadProfileEventsFromDatabase:(NSString *)uid;
-(int)countProfileEventsFromDatabase;
-(NSString*)getLatestProfileEventDateFromDatabase;
-(void)createCachedProfileHeaderTable;

#pragma mark ---- Status ----
-(void)putStatus:(NSString*)status;
-(void)putUserName:(NSString*)userName profileBlob:(NSData *)blob;
-(void)loadCachedProfileHeaderFromDatabase;

#pragma mark --- cached relationships ----
-(void)createCachedRelationshipsTable;
-(void)createCachedRelationshipsTagsTable;
-(void)saveRelationshipsToDatabase;
-(void)clearRelationshipTables:(sqlite3 *) database;
-(void)loadCachedRelationshipsFromDatabase:(NSString *)uid;

#pragma mark ---- cached messages ----
-(void)createCachedMessagesTable;
-(void)saveMessagesToDatabase:(BOOL)clear;
-(int)countCachedMessagesFromDatabase;

-(void)resetCachedTables;

#pragma mark ---- xml file funcs ---
-(void)saveContactsXML:(NSString*)xml;
-(void)loadContactsXML;
-(void)loadMessagesXML;
-(void)saveMessagesXML:(NSString*)xml;
-(void)loadSentMessagesXML;
-(void)saveSentMessagesXML:(NSString*)xml;
-(void)loadRelationshipsXML;
-(void)saveRelationshipsXML:(NSString*)xml;
-(void)loadEventsXML;
-(void)saveEventsXML:(NSString*)xml;
-(void)saveProfileEventsXML:(NSString*)xml;
-(void)loadProfileEventsXML;

@end
